home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Online / Apache / bin / apachectl < prev    next >
Encoding:
Text File  |  2001-06-06  |  7.0 KB  |  234 lines

  1. #!/bin/sh
  2. #
  3. # Apache control script designed to allow an easy command line interface
  4. # to controlling Apache.  Written by Marc Slemko, 1997/08/23
  5. # The exit codes returned are:
  6. #    0 - operation completed successfully
  7. #    1 - 
  8. #    2 - usage error
  9. #    3 - httpd could not be started
  10. #    4 - httpd could not be stopped
  11. #    5 - httpd could not be started during a restart
  12. #    6 - httpd could not be restarted during a restart
  13. #    7 - httpd could not be restarted during a graceful restart
  14. #    8 - configuration syntax error
  15. #
  16. # When multiple arguments are given, only the error from the _last_
  17. # one is reported.  Run "apachectl help" for usage info
  18. #
  19. #
  20. # |||||||||||||||||||| START CONFIGURATION SECTION  ||||||||||||||||||||
  21. # --------------------                              --------------------
  22. # the path to your PID file
  23. PIDFILE=/Apache/logs/httpd.pid
  24. #
  25. # the path to your httpd binary, including options if necessary
  26. HTTPD=/Apache/bin/httpd
  27. HTTPDSUID=/Apache/bin/starthttpd
  28. #
  29. # a command that outputs a formatted text version of the HTML at the
  30. # url given on the command line.  Designed for lynx, however other
  31. # programs may work.  
  32. LYNX="lynx -dump"
  33. #
  34. # the URL to your server's mod_status status page.  If you do not
  35. # have one, then status and fullstatus will not work.
  36. STATUSURL="http://localhost/server-status"
  37. #
  38. # --------------------                              --------------------
  39. # ||||||||||||||||||||   END CONFIGURATION SECTION  ||||||||||||||||||||
  40.  
  41. ERROR=0
  42. ARGV="$@"
  43. if [ "x$ARGV" = "x" ] ; then 
  44.     ARGS="help"
  45. fi
  46.  
  47. for ARG in $@ $ARGS
  48. do
  49.     # check for pidfile
  50.     if [ -f $PIDFILE ] ; then
  51.     PID=`cat $PIDFILE`
  52.     if [ "x$PID" != "x" ] && kill -0 $PID 2>/dev/null ; then
  53.         STATUS="httpd (pid $PID) running"
  54.         RUNNING=1
  55.     else
  56.         STATUS="httpd (pid $PID?) not running"
  57.         RUNNING=0
  58.     fi
  59.     else
  60.     STATUS="httpd (no pid file) not running"
  61.     RUNNING=0
  62.     fi
  63.  
  64.     case $ARG in
  65.     start)
  66.     if [ $RUNNING -eq 1 ]; then
  67.         echo "$0 $ARG: httpd (pid $PID) already running"
  68.         continue
  69.     fi
  70.     if $HTTPDSUID ; then
  71.         echo "$0 $ARG: httpd started"
  72.     else
  73.         echo "$0 $ARG: httpd could not be started"
  74.         ERROR=3
  75.     fi
  76.     ;;
  77.     stop)
  78.     if [ $RUNNING -eq 0 ]; then
  79.         echo "$0 $ARG: $STATUS"
  80.         continue
  81.     fi
  82.     if kill $PID ; then
  83.         echo "$0 $ARG: httpd stopped"
  84.     else
  85.         echo "$0 $ARG: httpd could not be stopped"
  86.         ERROR=4
  87.     fi
  88.     ;;
  89.     restart)
  90.     if [ $RUNNING -eq 0 ]; then
  91.         echo "$0 $ARG: httpd not running, trying to start"
  92.         if $HTTPDSUID ; then
  93.         echo "$0 $ARG: httpd started"
  94.         else
  95.         echo "$0 $ARG: httpd could not be started"
  96.         ERROR=5
  97.         fi
  98.     else
  99.         if $HTTPD -t >/dev/null 2>&1; then
  100.         if kill -HUP $PID ; then
  101.             echo "$0 $ARG: httpd restarted"
  102.         else
  103.             echo "$0 $ARG: httpd could not be restarted"
  104.             ERROR=6
  105.         fi
  106.         else
  107.         echo "$0 $ARG: configuration broken, ignoring restart"
  108.         echo "$0 $ARG: (run 'apachectl configtest' for details)"
  109.         ERROR=6
  110.         fi
  111.     fi
  112.     ;;
  113.     graceful)
  114.     if [ $RUNNING -eq 0 ]; then
  115.         echo "$0 $ARG: httpd not running, trying to start"
  116.         if $HTTPDSUID ; then
  117.         echo "$0 $ARG: httpd started"
  118.         else
  119.         echo "$0 $ARG: httpd could not be started"
  120.         ERROR=5
  121.         fi
  122.     else
  123.         if $HTTPD -t >/dev/null 2>&1; then
  124.         if kill -USR1 $PID ; then
  125.             echo "$0 $ARG: httpd gracefully restarted"
  126.         else
  127.             echo "$0 $ARG: httpd could not be restarted"
  128.             ERROR=7
  129.         fi
  130.         else
  131.         echo "$0 $ARG: configuration broken, ignoring restart"
  132.         echo "$0 $ARG: (run 'apachectl configtest' for details)"
  133.         ERROR=7
  134.         fi
  135.     fi
  136.     ;;
  137.     status)
  138.     $LYNX $STATUSURL | awk ' /process$/ { print; exit } { print } '
  139.     ;;
  140.     fullstatus)
  141.     $LYNX $STATUSURL
  142.     ;;
  143.     configtest)
  144.     if $HTTPD -t; then
  145.         :
  146.     else
  147.         ERROR=8
  148.     fi
  149.     ;;
  150.     *)
  151.     echo "usage: $0 (start|stop|restart|fullstatus|status|graceful|configtest|help)"
  152.     cat <<EOF
  153.  
  154. start      - start httpd
  155. stop       - stop httpd
  156. restart    - restart httpd if running by sending a SIGHUP or start if 
  157.              not running
  158. fullstatus - dump a full status screen; requires lynx and mod_status enabled
  159. status     - dump a short status screen; requires lynx and mod_status enabled
  160. graceful   - do a graceful restart by sending a SIGUSR1 or start if not running
  161. configtest - do a configuration syntax test
  162. help       - this screen
  163.  
  164. EOF
  165.     ERROR=2
  166.     ;;
  167.  
  168.     esac
  169.  
  170. done
  171.  
  172. exit $ERROR
  173.  
  174. ## ====================================================================
  175. ## The Apache Software License, Version 1.1
  176. ##
  177. ## Copyright (c) 2000 The Apache Software Foundation.  All rights
  178. ## reserved.
  179. ##
  180. ## Redistribution and use in source and binary forms, with or without
  181. ## modification, are permitted provided that the following conditions
  182. ## are met:
  183. ##
  184. ## 1. Redistributions of source code must retain the above copyright
  185. ##    notice, this list of conditions and the following disclaimer.
  186. ##
  187. ## 2. Redistributions in binary form must reproduce the above copyright
  188. ##    notice, this list of conditions and the following disclaimer in
  189. ##    the documentation and/or other materials provided with the
  190. ##    distribution.
  191. ##
  192. ## 3. The end-user documentation included with the redistribution,
  193. ##    if any, must include the following acknowledgment:
  194. ##       "This product includes software developed by the
  195. ##        Apache Software Foundation (http://www.apache.org/)."
  196. ##    Alternately, this acknowledgment may appear in the software itself,
  197. ##    if and wherever such third-party acknowledgments normally appear.
  198. ##
  199. ## 4. The names "Apache" and "Apache Software Foundation" must
  200. ##    not be used to endorse or promote products derived from this
  201. ##    software without prior written permission. For written
  202. ##    permission, please contact apache@apache.org.
  203. ##
  204. ## 5. Products derived from this software may not be called "Apache",
  205. ##    nor may "Apache" appear in their name, without prior written
  206. ##    permission of the Apache Software Foundation.
  207. ##
  208. ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  209. ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  210. ## OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  211. ## DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  212. ## ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  213. ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  214. ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  215. ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  216. ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  217. ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  218. ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  219. ## SUCH DAMAGE.
  220. ## ====================================================================
  221. ##
  222. ## This software consists of voluntary contributions made by many
  223. ## individuals on behalf of the Apache Software Foundation.  For more
  224. ## information on the Apache Software Foundation, please see
  225. ## <http://www.apache.org/>.
  226. ##
  227. ## Portions of this software are based upon public domain software
  228. ## originally written at the National Center for Supercomputing Applications,
  229. ## University of Illinois, Urbana-Champaign.
  230. ##
  231.